//
//  JMMeDateWarningPopupView.m
//  NewiOSProject
//
//  Created by li on 2023/9/26.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMMeDateWarningPopupView.h"
#import "LayoutView.h"

#import "JMPickerSelectionView.h"
#import "JMPickerSelectionModel.h"
#import "PaddingView.h"
#import "LayoutScrollView.h"
#import "CustomStackView.h"
#import "UIView+PopupProtocol.h"

@interface JMMeDateWarningPopupView ()
@property(nonatomic, strong) CAGradientLayer *gl;
@end

@implementation JMMeDateWarningPopupView
@synthesize modalStyle;
@synthesize translucentView;
@synthesize dismissCompletion;

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.translucentView = [self defaultTranslucentView];
        
        self.modalStyle = PopupViewModalStyleFromBottom;
        
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    CustomStackView *rootStack = [CustomStackView init:(UILayoutConstraintAxisVertical)];
    
    rootStack.translatesAutoresizingMaskIntoConstraints = NO;
    rootStack.spacing = 20;
    [self addSubview:rootStack];
    [NSLayoutConstraint activateConstraints:@[
        [rootStack.topAnchor constraintEqualToAnchor:self.topAnchor constant:0],
        [rootStack.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:0],
        [rootStack.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:0],
        [rootStack.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:0],
    ]];
    
    UIButton *close = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [close setImage:[UIImage imageNamed:@"close_white"] forState:(UIControlStateNormal)];
    close.frame = CGRectMake(0, 0, 44, 44);
    [close addTarget:self action:@selector(closeAtion:) forControlEvents:(UIControlEventTouchUpInside)];
    CustomStackView *closeStack = [CustomStackView init:(UILayoutConstraintAxisVertical)];
    [closeStack addArrangedSubview:close];
    closeStack.alignment = UIStackViewAlignmentTrailing;
    [closeStack.widthAnchor constraintEqualToConstant:kScreenWidth].active = YES;
    [rootStack addArrangedSubview:[PaddingView initWithContentView:closeStack edgeInsets:(UIEdgeInsetsMake(0, 0, 0, 20))]];
    
    CustomStackView *contentStack = [CustomStackView init:(UILayoutConstraintAxisVertical)];
    contentStack.alignment = UIStackViewAlignmentCenter;
    contentStack.spacing = 20;
    
    UILabel *titleLab = [UILabel new];
    titleLab.numberOfLines = 0;
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.text = @"Caduca el informe de crédito?";
    titleLab.textColor = [UIColor colorWithHexString:@"#0F1511"];
    titleLab.font = [UIFont systemFontOfSize:14 weight:(UIFontWeightMedium)];
    [contentStack addArrangedSubview:titleLab];
    
    UILabel *contentLab = [UILabel new];
    contentLab.numberOfLines = 0;
    self.contentLab = contentLab;
    contentLab.textAlignment = NSTextAlignmentLeft;
//    contentLab.lineBreakMode = NSLineBreakByCharWrapping;
   
    
    contentLab.text = @"En general, las puntuaciones FICO@scores no cambian mucho con el tiempo. Pero es importante tener en cuenta que su puntuación FICO se calcula cada vez que se solicita, ya sea por usted o por un prestamista. Y cada vez que se calcula, se actualiza la información que figura en su informe crediticio en ese momento. Por lo tanto, a medida que cambia la información de su informe de crédito, también puede cambiar su puntuación FICO.\nSe recomienda que proporcione un informe de crédito actualizado para que los prestamistas puedan evaluar su crédito con precisión.";
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:contentLab.text];
    attr.yy_lineSpacing = 5;
    contentLab.attributedText = attr;
    
    contentLab.textColor = [UIColor colorWithHexString:@"#959892"];
    contentLab.font = [UIFont systemFontOfSize:12];
    [contentStack addArrangedSubview:contentLab];

    
    
    [rootStack addArrangedSubview:[[PaddingView initWithContentView:contentStack edgeInsets:(UIEdgeInsetsMake(43, 25, 40, 25))] then:^(PaddingView * _Nonnull view) {
        
        view.backgroundColor = [UIColor whiteColor];
        view.layer.cornerRadius = 30;
        view.layer.masksToBounds = YES;
//        [view.layer insertSublayer:self.gl atIndex:0];
        UIImageView *imageView = [UIImageView new];
        imageView.image = [UIImage imageNamed:@"me_bg_4"];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        [view insertSubview:imageView atIndex:0];
        imageView.translatesAutoresizingMaskIntoConstraints = NO;
        [NSLayoutConstraint activateConstraints:@[
            [imageView.topAnchor constraintEqualToAnchor:view.topAnchor],
            [imageView.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],
            [imageView.widthAnchor constraintEqualToAnchor:view.widthAnchor],
            [imageView.heightAnchor constraintEqualToAnchor:view.heightAnchor]
        ]];

    }]];
    
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}

- (void)configureLayer {
    CAGradientLayer *gl = [CAGradientLayer layer];
    self.gl = gl;
    gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    gl.startPoint = CGPointMake(0.5, 0.04);
    gl.endPoint = CGPointMake(0.5, 0.37);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:251/255.0 green:255/255.0 blue:211/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
}

- (void)closeAtion: (UIButton *)sender {
    [self dismissPopup];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
